#include "Item.hh"
#include "Player.hh"
#include "Character.hh"
#include <iostream>

namespace DungeonRPG {

// Item constructor: initializes all properties
Item::Item(const std::string& name,
           const std::string& description,
           int healthBoost,
           int attackBoost,
           int defenseBoost,
           ItemType type)
    : name(name),
      description(description),
      healthBoost(healthBoost),
      attackBoost(attackBoost),
      defenseBoost(defenseBoost),
      type(type) {}

std::string Item::getName() const {
    return name;
}

std::string Item::getDescription() const {
    return description;
}

Item* Item::clone() const {
    // Clone creates a heap copy of this item for inventory/shop use
    auto* copy = new Item(name, description, healthBoost, attackBoost, defenseBoost, type);
    copy->ownedByRoom = true;
    return copy;
}

bool Item::use(Character* target) {
    if (!target) return false;

    // Use item based on its type
    switch (type) {
    case ItemType::Food:
        target->relieveStress(10);
        target->heal(10);
        return true;

    case ItemType::Bandage:
        target->relieveStress(5);
        return true;

    case ItemType::HolyWater:
        target->relieveStress(15);
        return true;

    case ItemType::Torch:
        target->relieveStress(7);
        return true;

    case ItemType::Scroll:
        // Scroll teaches a skill if used by a Player
        if (Player* p = dynamic_cast<Player*>(target)) {
            p->learnSkill(specialSkill);
            return true;
        }
        return false;

    case ItemType::Equipment:
        // Equipment must be manually equipped
        std::cout << name << " added to inventory. You must equip it manually.\n";
        return false;
    }

    return false;
}

// Static equipment item definitions
Item LuckyCharm(
    "Lucky Charm", "DEF+3", 0, 0, 3, ItemType::Equipment);

Item RustyRing(
    "Rusty Ring", "ATK+2", 0, 2, 0, ItemType::Equipment);

Item SharpTrinket(
    "Sharp Trinket", "Boosts ATK by 10.", 0, 10, 0, ItemType::Equipment);

Item HeavyPendant(
    "Heavy Pendant", "Boosts DEF by 10.", 0, 0, 10, ItemType::Equipment);

Item VirtueBadge(
    "Virtue Badge", "Boosts defense and reduces stress.", 0, 0, 5, ItemType::Equipment);

Item BloodCharm(
    "Blood Charm", "Increases max health and attack.", 10, 5, 0, ItemType::Equipment);

Item OccultNecklace(
    "Occult Necklace", "Mystical power pulses through.", 0, 0, 8, ItemType::Equipment);

}
